<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<% content_for :page_title do %><%= t '#crumbs.groups', 'Groups' %><% end %>
<% add_crumb t('#crumbs.groups', 'Groups') %>

<% content_for :right_side do %>
<% end %>

<% css_bundle :course_list %>

  <h2><%= t :heading_current_groups, 'Current Groups' %></h2>
  <% if @current_groups.empty? %>
    {{#t}}No Groups{{/t}}
  <% else %>
    <table id="my_groups_table" class="ic-Table ic-Table--bordered">
      <thead>
        <tr>
          <th scope="col" class="course-list-group-column">{{#t}}Group{{/t}}</th>
          <th scope="col" class="course-list-course-title-column course-list-no-left-border">{{#t}}Course{{/t}}</th>
          <th scope="col" class="course-list-term-column course-list-no-left-border">{{#t}}Term{{/t}}</th>
        </tr>
      </thead>
      <tbody>
        <% @current_groups.each do |group| %>
          <tr>
            <td>
              <%= link_to group.name, group_path(group) %>
            </td>
            <td class="course-list-no-left-border">
              <span class="group-course-name"><%= group.context.name %></span>
            </td>
            <td class="course-list-no-left-border">
              <% if group.context_type == 'Course' && !group.context.enrollment_term.default_term? %>
               <%= group.context.enrollment_term.name %>
              <% end %>
            </td>
          </tr>
        <% end %>
      </tbody>
    </table>
  <% end %>

  <h2><%= t :heading_previous_groups, 'Previous Groups' %></h2>
  <% if @previous_groups.empty? %>
    {{#t}}No Groups{{/t}}
  <% else %>
    <table id="my_groups_table" class="ic-Table ic-Table--bordered">
      <thead>
        <tr>
          <th scope="col" class="course-list-group-column">{{#t}}Group{{/t}}</th>
          <th scope="col" class="course-list-course-title-column course-list-no-left-border">{{#t}}Course{{/t}}</th>
          <th scope="col" class="course-list-term-column course-list-no-left-border">{{#t}}Term{{/t}}</th>
        </tr>
      </thead>
      <% @previous_groups.each do |group| %>
        <tr>
          <td>
            <%# Only show a link if the user can read the group - they'll get a permissions error page if they try to %>
            <%# hit the link otherwise %>
            <% if group.grants_right?(@current_user, session, :read) %>
              <%= link_to group.name, group_path(group) %>
            <% else %>
              <%= group.name %>
            <% end %>
          </td>
          <td>
            <%= group.context.name %>
          </td>
          <td>
            <% if group.context_type == 'Course' && !group.context.enrollment_term.default_term? %>
              <span class="screenreader-only"><%= group.context.enrollment_term.name %></span>
            <% else %>
              <%= group.context.enrollment_term.name %>
            <% end %>
          </td>
        </tr>
      <% end %>
    </table>
  <% end %>

